# @summary A short summary of the purpose of this class
#
# A description of what this class does
#
# @example
#   include eos::client
class eos::client(
  $enable_eos    = true,
  $enable_autofs = true,
  $login_node    = false,
)
{

if $enable_eos {
    package { "eos-config-ui":
      ensure   => "absent",
    }
    package { "eos-config":
      ensure   => "absent",
    }
  case $facts['os']['release']['major'] {
  '7' :{
    yumrepo { "eos":
          baseurl => "http://${mirrorserver}/yum/storage-ci/eos/diopside/sl-${facts['os']['release']['major']}-x86_64/5.1.25",
          descr => "eos repository",
          enabled => 1,
          gpgcheck => 0,
          priority => 1,
          before   => Yumrepo['site']
    }
    yumrepo { "eos-depends":
          baseurl => "http://${mirrorserver}/yum/storage-ci/eos/diopside/sl-${facts['os']['release']['major']}-x86_64-depends",
          descr => "eos depends repository",
          enabled => 1,
          gpgcheck => 0,
          priority => 1,
          before   => Yumrepo['site']
    }
  }
  /8|9/ :{
    yumrepo { "eos":
          baseurl => "http://${mirrorserver}/yum/storage-ci/eos/diopside/el-${facts['os']['release']['major']}",
          descr => "eos repository",
          enabled => 1,
          gpgcheck => 0,
          priority => 1,
          before   => Yumrepo['site']
    }
    yumrepo { "eos-depends":
          baseurl => "http://${mirrorserver}/yum/storage-ci/eos/diopside/el-${facts['os']['release']['major']}-depends",
          descr => "eos depends repository",
          enabled => 1,
          gpgcheck => 0,
          priority => 1,
          before   => Yumrepo['site']
    }

  }
  }


  if 0 + $facts['os']['release']['major']  >=7 {
    package { ["xrootd-client",
            "xrootd-devel",
            "xrootd-client-libs",
            "xrootd-libs"]:
        ensure   => "installed",
        require  => Yumrepo['site'],
    }
  }
  else {
    package { ["xrootd-client",
                  "xrootd-devel",
                  "xrootd-client-libs",
                  "xrootd-compat-client-libs",
                  "xrootd-compat-libs",
                  "xrootd-libs"]:
        ensure   => "installed",
        require  => Yumrepo['site'],
    }
  }
  package { ["eos-client",
             "eos-fusex",
             "eos-fusex-selinux",
             "eos-fusex-core"]:
    ensure   => "installed",
    require  => Yumrepo['site']
  } 

  if "ture" {

    if $login_node{
        file {"/etc/auto.master.d/eos.autofs":
          notify       =>  Service['autofs'],
          mode         =>  '644',
          owner        =>  'root',
          group        =>  'root',
          source       =>  "puppet:///modules/${module_name}/login_eos.autofs",
        }
      file {"/etc/auto.eos":
        notify       =>  Service['autofs'],
        mode         =>  '644',
        owner        =>  'root',
        group        =>  'root',
        source       =>  "puppet:///modules/${module_name}/login_auto.eos",
      }
      file {"/etc/eos":
        notify       =>  Service['autofs'],
        mode         =>  '0755',
        owner        =>  'root',
        group        =>  'root',
        source       =>  "puppet:///modules/${module_name}/login_etc_eos",
        recurse      =>   true,
        ensure       =>   directory,
        force        =>   true,
      }
      if 0 + $facts['os']['release']['major'] >=9 {    
        augeas { "autofs_conf":
          context => '/files/etc/autofs.conf',
          lens    => 'Puppet.lns',
          incl    => '/etc/autofs.conf',
          changes => [
            "set \ autofs\ /browse_mode yes",
          ],
          notify  =>  Service['autofs'],
        }
      }
    }
    else {
        file {"/etc/auto.master.d/eos.autofs":
          notify       =>  Service['autofs'],
          mode         =>  '644',
          owner        =>  'root',
          group        =>  'root',
          source       =>  "puppet:///modules/${module_name}/client_eos.autofs",
        }
      file {"/etc/auto.eos":
        notify       =>  Service['autofs'],
        mode         =>  '644',
        owner        =>  'root',
        group        =>  'root',
        source       =>  "puppet:///modules/${module_name}/client_auto.eos",
      }
      file {"/etc/eos":  
        notify       =>  Service['autofs'],
        mode         =>  '0755',
        owner        =>  'root',
        group        =>  'root',
        source       =>  "puppet:///modules/${module_name}/client_etc_eos",
        recurse      =>   true,
        ensure       =>   directory,
        force        =>   true,
      }
    }
    }
  
    service { "eosd":
      hasrestart => true,
      ensure     => false,
      enable     => false,
      hasstatus  => true,
    }
  }
}
